By moving a component's variable initialization routines from its init method to its awake method and implementing a sleep method to release those variables, you can reduce the space requirements for storing a component. For example, the code shown in the section "Component Objects and Component State" could be changed to:
// rewritten Main.wosNote that in WebScript you set a variable to nil to mark it for release. In Objective-C you send the object a release message:
id models, model, selectedModels;
id prices, price, selectedPrices;
id types, type, selectedTypes;
- awake {
anApplication = [WOApplication application];
models = [[anApplication modelsDict] allValues];
types = [[anApplication typesDict] allValues];
prices = [anApplication prices];
}
- sleep {
models = nil;
types = nil;
prices = nil;
}
- sleep {Of course, what you save in storage by moving variable initialization to the awake method is lost in performance, since these variables will be reinitialized on each cycle of the request-response loop.
[models release];
models = nil;
[types release];
types = nil;
[prices release];
prices = nil;
}
Table of Contents
Next Section